package com.tanhua.server.service;

import com.tanhua.autoconfig.template.SmsTemplate;
import org.apache.commons.lang.RandomStringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
public class UserService {
    /**
     * 发送短信验证码方法
     * @param phone
     */
    @Autowired
   private SmsTemplate template;
    @Autowired
        private RedisTemplate<String,String> redisTemplate;
    public void sendMsg(String phone) {
          //  1.随机生成六位数字
        String code = RandomStringUtils.randomNumeric(6);
        //2.调用template对象，发送手机短信
            template.sendSms(phone,code);
        //3.将验证码存入redis
        redisTemplate.opsForValue().set("CHECK_CODE"+phone,code,Duration.ofMinutes(5));
    }
}
